
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { createRouter, createWebHashHistory } from 'vue-router'

// 路由配置
const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/Home/index.vue')
  },
  {
    path: '/detail/:id',
    name: 'Detail',
    component: () => import('@/views/Detail/index.vue')
  },
  {
    path: '/uploadDetail/:id',
    name: 'UploadDetail',
    component: () => import('@/views/UploadDetail/index.vue')
  },
  {
    path: '/personalCenter',
    name: 'PersonalCenter',
    component: () => import('@/views/PersonalCenter/index.vue')
  },
  {
    path: '/purchaseRecord',
    name: 'PurchaseRecord',
    component: () => import('@/views/purchaseRecord/index.vue')
  },
  {
    path: '/protocol/user',
    name: 'protocolUser',
    component: () => import('@/views/Protocol/user.vue')
  },
  {
    path: '/protocol/privacyPolicy',
    name: 'privacyPolicy',
    component: () => import('@/views/Protocol/privacyPolicy.vue')
  },
  {
    path: '/protocol/purchase',
    name: 'protocolPurchase',
    component: () => import('@/views/Protocol/purchase.vue')
  }
]

// 创建路由实例
const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior() {
    return { top: 0 }
  }
})

router.beforeEach((to, from, next) => {
  NProgress.start()
  console.log(`路由跳转: ${from.path} -> ${to.path}`)
  next()
})


router.afterEach(() => {
  NProgress.done() // 结束进度条
})

export default router